package com.bangcommunity.bbframe.dynconfig.dynlog;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;

/**
 * @author tanghc
 * @date 18/1/29
 */
public class Log4jModifier {

    public static void modifyLoggerLevel(String loggerName, String level) {
        try {
            Logger logger = Logger.getLogger(loggerName.trim());
            if (logger != null) {
                level = level.trim();
                if ("INFO".equalsIgnoreCase(level)) {
                    logger.setLevel(Level.INFO);
                } else if ("DEBUG".equalsIgnoreCase(level)) {
                    logger.setLevel(Level.DEBUG);
                } else if ("WARN".equalsIgnoreCase(level)) {
                    logger.setLevel(Level.WARN);
                } else if ("ERROR".equalsIgnoreCase(level)) {
                    logger.setLevel(Level.ERROR);
                } else if ("FATAL".equalsIgnoreCase(level)) {
                    logger.setLevel(Level.FATAL);
                } else if ("ALL".equalsIgnoreCase(level)) {
                    logger.setLevel(Level.ALL);
                } else if ("OFF".equalsIgnoreCase(level)) {
                    logger.setLevel(Level.OFF);
                } else if ("TRACE".equalsIgnoreCase(level)) {
                    logger.setLevel(Level.TRACE);
                }
            }
        } catch (Throwable ignore) {
        }
    }

}